package com.bw.controller;

import com.alibaba.fastjson.JSONObject;
import com.bw.bean.Emp;
import com.bw.bean.UserInfo;
import com.bw.service.EmpService;
import com.bw.service.EmpServiceImpl;
import com.bw.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author admin
 * @date 2025年09月19日 10:06
 */
@RestController
public class EmpController {
    @Autowired
    private EmpServiceImpl empService;

    @RequestMapping("/insert1")
    public JSONObject insert1(Emp emp){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg","添加");
        Emp emp1 = new Emp();
        emp1.setName("ww");
        emp1.setSex("男");
        Date date = new Date();
        emp1.setBirth(date);
        emp1.setSalary(50.5);
        int insert = empService.insert(emp1);

        if(insert>0){
            jsonObject.put("code","添加成功");
        }else {
            jsonObject.put("code","添加失败");
        }

        return jsonObject;
    }
    @RequestMapping("/update1")
    public JSONObject update(Emp emp){

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg","更新");

        Emp emp1 = empService.selectId(1);
        System.out.println(emp1);
        emp1.setName("好好");
        int update = empService.update(emp1);
        if(update>0){
            jsonObject.put("code","更新成功");
        }else {
            jsonObject.put("code","更新失败");
        }
        return jsonObject;
    }

    @RequestMapping("/delect1")
    public JSONObject delect(Integer id){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg","删除");
        int insert = empService.delect(2);
        if(insert>0){
            jsonObject.put("code","删除成功");
        }else {
            jsonObject.put("code","删除失败");
        }
        return jsonObject;
    }
    @RequestMapping("/selectAll1")
    public List<Emp> selectAll(){
        return empService.selectAll();
    }
    @RequestMapping("/selectId1")
    public Emp selectId(){
        return empService.selectId(1);
    }
}
